<template>
	<el-container>
		<el-header>
			<el-page-header content="添加工作流" @back="goBack" />
            <div><el-button type="primary" @click="addflow">保存工作流</el-button></div>
		</el-header>
		<el-main>
			<sc-workflow v-model="data.nodeConfig"></sc-workflow>
		</el-main>
	</el-container>
</template>

<script>
	import scWorkflow from '@/components/scWorkflow'

	export default {
		name: 'addflow',
        components: {
			scWorkflow
		},
		data() {
			return {
				openId:null,
				data:{},
				defaultdata: {
					'nodeId':this.generateUUID(),
					"name": "请假审批",
					"nodeConfig": {
						'nodeId':this.generateUUID(),
						"nodeName": "发起人",
						"type": 0,
						"nodeRoleList": [],
						"childNode": {
							'nodeId':this.generateUUID(),
							"nodeName": "条件路由",
							"type": 4,
							"conditionNodes": [{
									'nodeId':this.generateUUID(),
									"nodeName": "长期",
									"type": 3,
									"priorityLevel": 1,
									"conditionMode": 1,
									"conditionList": [{
										"label": "请假天数",
										"field": "day",
										"operator": ">",
										"value": "7"
									}],
									"childNode": {
										'nodeId':this.generateUUID(),
										"nodeName": "领导审批",
										"type": 1,
										"setType": 1,
										"nodeUserList": [{
											"id": "360000197302144442",
											"name": "何敏"
										}],
										"nodeRoleList": [],
										"examineLevel": 1,
										"directorLevel": 1,
										"selectMode": 1,
										"termAuto": false,
										"term": 0,
										"termMode": 1,
										"examineMode": 1,
										"directorMode": 0
									}
								},
								{
									'nodeId':this.generateUUID(),
									"nodeName": "短期",
									"type": 3,
									"priorityLevel": 2,
									"conditionMode": 1,
									"conditionList": [],
									"childNode": {
										'nodeId':this.generateUUID(),
										"nodeName": "直接主管审批",
										"type": 1,
										"setType": 2,
										"nodeUserList": [],
										"nodeRoleList": [],
										"examineLevel": 1,
										"directorLevel": 1,
										"selectMode": 1,
										"termAuto": false,
										"term": 0,
										"termMode": 1,
										"examineMode": 1,
										"directorMode": 0
									}
								}
							],
							"childNode": {
								'nodeId':this.generateUUID(),
								"nodeName": "抄送人",
								"type": 2,
								"userSelectFlag": true,
								"nodeUserList": [{
									"id": "220000200908305857",
									"name": "何秀英"
								}]
							}
						}
					}
				}
			}
		},
		created(){
	
		},
		mounted() {
			let id=this.$route.query.id;
			this.openId=id;
			if(id){
				this.getOne(id);
			}else{
				this.data=this.defaultdata;
			}
			
		},
		methods: {
			async getOne(id){
				let data={'id':id};
				var res = await this.$API.flow.getflow.get(data);
				if(res.code==200){
					this.data=JSON.parse(res.data.flowJson)
				}
			},
			async addflow(){
				let data={flowJson:this.data};
				if(this.openId){
					data.id=this.openId;
				}
				var res = await this.$API.flow.addOrUpdateFlow.post(data);
			},
			goBack(){
				this.$router.go(-1)
			},
            exportJson() {
				this.$message("返回值请查看F12控制台console.log()")
				
				console.log(JSON.stringify(this.data))
			},
			generateUUID(){
				return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
					var r = Math.random() * 16 | 0,
						v = c == 'x' ? r : (r & 0x3 | 0x8);
					return v.toString(16);
				});
			}
		}
	}
</script>

<style>
</style>
